package com.richly.controller;

import cn.hutool.http.HttpStatus;
import com.richly.dto.TestDataDto;
import com.richly.dto.base.Recordable;
import com.richly.iot.IotDbUtils;
import com.richly.iot.IotWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: l_y
 * @Date: 2022/6/17 14:16
 * @FileName: TestController
 * @Description:
 */
@RestController
public class TestController {

    @Autowired
    private IotDbUtils iotDbUtils;

    @GetMapping("save")
    public Object save() {
        TestDataDto dataDto = new TestDataDto();
        dataDto.setMoney(BigDecimal.TEN);
        dataDto.setName("测试数据" + UUID.randomUUID());
        dataDto.setDataTime(new Date());
        iotDbUtils.insertDataToIot(Collections.singletonList(dataDto));
        return HttpStatus.HTTP_OK + "";
    }

    @GetMapping("get")
    public Object get() {
        IotWrapper wrapper = new IotWrapper();
//        wrapper.gt("money",5);
//        wrapper.lt("money",5);
//        wrapper.eq("name","测试");
        List<Recordable> list = iotDbUtils.queryDataToIot(TestDataDto.class, wrapper);
        return list;
    }

}
